package com.xuecheng.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.basic.domain.Dictionary;
import com.xuecheng.basic.mappers.DictionaryMapper;
import com.xuecheng.basic.service.DictionaryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.commons.model.vo.DictionaryVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.utils.BeanHelper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 数据字典 服务实现类
 * </p>
 *
 * @author itheima
 * @since 2022-09-19
 */
@Service
public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Dictionary> implements DictionaryService {
    //查找所有数据字典
    @Override
    public ResponseResult<List<DictionaryVo>> findAll() {
        List<Dictionary> list = this.list();
        List<DictionaryVo> vos = BeanHelper.copyWithCollection(list, DictionaryVo.class);
        return ResponseResult.okResult(vos);
    }
    //根据code查询数据字典
    @Override
    public ResponseResult<DictionaryVo> findByCode(String code) {
        //1.设置查询条件
        LambdaQueryWrapper<Dictionary> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Dictionary::getCode,code);
        //2.查询
        Dictionary dictionary = this.getOne(wrapper);
        DictionaryVo dictionaryVo = BeanHelper.copyProperties(dictionary, DictionaryVo.class);
        return ResponseResult.okResult(dictionaryVo);
    }

}
